import tkinter as tk
from tkinter import messagebox
import time
import os

class AutoRestartApp:
    def __init__(self, root):
        self.root = root
        root.title("杀毒软件升级提醒")

        # 创建按钮
        self.btn_now = tk.Button(root, text="立即重启", command=self.restart_now)
        self.btn_now.pack(pady=10)

        self.btn_10s = tk.Button(root, text="10秒后重启", command=lambda: self.restart_in_seconds(10))
        self.btn_10s.pack(pady=10)

        self.btn_2h = tk.Button(root, text="2小时后重启", command=lambda: self.restart_in_seconds(2 * 60 * 60))
        self.btn_2h.pack(pady=10)

        # 添加底部提示信息的Label
        self.status_label = tk.Label(root, text="杀毒软件升级完成，请保存数据后立即重启计算机。", bd=1, relief=tk.SUNKEN, anchor=tk.W)
        self.status_label.pack(side=tk.BOTTOM, fill=tk.X)

        # 捕获窗口关闭事件
        root.protocol("WM_DELETE_WINDOW", self.on_close)

        # 设置窗口居中显示
        window_width = 300
        window_height = 200
        screen_width = root.winfo_screenwidth()
        screen_height = root.winfo_screenheight()
        x = (screen_width - window_width) // 2
        y = (screen_height - window_height) // 2
        root.geometry(f"{window_width}x{window_height}+{x}+{y}")

    def restart_now(self):
        self.show_message("重启计划已设置，将立即重启。")
        self.restart(0)

    def restart_in_seconds(self, seconds):
        self.show_message(f"重启计划已设置，将在{seconds}秒后重启。")
        self.restart(seconds)

    def restart(self, seconds):
        time.sleep(seconds)
        os.system("shutdown /r /t 0")

    def show_message(self, message):
        messagebox.showinfo("提示", message)

    def on_close(self):
        # 禁止默认的关闭行为，显示消息框
        self.show_message("请使用应用程序按钮设置重启计划。")

if __name__ == "__main__":
    root = tk.Tk()
    app = AutoRestartApp(root)
    root.mainloop()
